
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.model.JobPreScript;
import com.dps.omc.service.IJobPreScriptService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class JobPreScriptAction extends AbstractAdminController<IJobPreScriptService>{

    @Autowired
    private IJobPreScriptService jobPreScriptService;
    
    @RequestMapping(value="/jobprescript/list")
    public String list(JobPreScript jobPreScript, ModelMap model, PageParam pageParam, HttpServletRequest request, HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(jobPreScript); 	
    	BizData4Page<JobPreScript> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("jobPreScript", jobPreScript);
    	return "/module/jobprescript/list";
    }    
    
    @RequestMapping(value="/jobprescript/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("jobPreScript", new JobPreScript());
        return "module/jobprescript/edit";
    }    
    
    @RequestMapping(value="/jobprescript/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	JobPreScript jobPreScript = jobPreScriptService.fetch(id);
    	model.addAttribute("jobPreScript", jobPreScript);
        return "module/jobprescript/edit";
    }    
    
    @RequestMapping(value="/jobprescript/save")
    @ResponseBody
    public String save(HttpServletRequest request,JobPreScript jobPreScript){
		boolean isAddNew = StringUtils.isBlank(jobPreScript.getId())?true:false;
		if(isAddNew)
		{
			jobPreScript.setId(IdGenerator.createNewId());
			jobPreScriptService.add(jobPreScript);
		}
		else
		{
			jobPreScriptService.update(jobPreScript);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/jobprescript/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	jobPreScriptService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(JobPreScript jobPreScript)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("jobId", jobPreScript.getJobId());		
		conditions.put("preScriptId", jobPreScript.getPreScriptId());		
		conditions.put("artifactName", jobPreScript.getArtifactName());		
		conditions.put("storePath", jobPreScript.getStorePath());		
		conditions.put("storeName", jobPreScript.getStoreName());		
		conditions.put("createDate", jobPreScript.getCreateDate());		
    	return conditions;
    }

    @Override
    protected IJobPreScriptService getMainService() {
        return jobPreScriptService;
    }

    @Override
    protected String getMainObjName() {
        return "jobprescript";
    }

    @Override
    protected String getViewTitle() {
        return "jobprescript";
    }
}
